﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;

namespace Directory.Web
{
	public partial class RecentAdd : System.Web.UI.Page
	{
		protected string LogoBasePath = ConfigurationManager.AppSettings["LogoBasePath"].Replace("~/", "/");
		protected void Page_Load(object sender, EventArgs e)
		{
			if (!IsPostBack)
			{
				rptItemsList.DataSource = ItemDataProxy.GetRecentAdded();
				rptItemsList.DataBind();
			}
		}

		protected void rptItemsList_ItemDataBound(object sender, RepeaterItemEventArgs e)
		{
			Directory.Model.ItemInfo item = (Directory.Model.ItemInfo)e.Item.DataItem;
			Literal lt = e.Item.FindControl("ltCategoryPath") as Literal;
			if (lt != null && item != null)
			{
				foreach (Directory.Model.CategoryInfo cat in CategoryDataProxy.GetRecursiveParentsOfCategory(item.CategoryId))
				{
					string link = string.Format("<a href='ItemView.aspx?categoryId={0}'>{1}</a>", cat.CategoryId.ToString(), cat.CategoryName);
					lt.Text += "»" + link;
				}
			}
		}
	}
}
